using System;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
using WindowsLive.Writer.Api;
namespace hMediaPlugIn
{
    [WriterPlugin
   ("0629A6DA-B8FC-481d-875D-F6FE2393CD37", "hMedia Plugin",
        PublisherUrl = "http://www.visitmix.com",
     Description = "Insert Audio and Video Formatted As hMedia", ImagePath = "microformats-16.png", HasEditableOptions = false)]
    [InsertableContentSource("Audio/Video (hMedia)")]
    public class Plugin : ContentSource
    {
        public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content)
        {
            try
            {
                hMedia c = this.GetContent(dialogOwner);
                if (c != null)
                {
                    content = FormatOutput(c);
                    return DialogResult.OK;
                }
                return DialogResult.Cancel;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return DialogResult.Cancel;
            }
            
        }
        private string FormatOutput(hMedia hmedia)
        {
            // Used to format the ListViewItem data for final HTML output
            StringBuilder html = new StringBuilder();
            
            html.Append("<div class='hMedia' >");
            html.Append("<span class='fn'>");
            html.Append(hmedia.FN);
            html.Append("</span> by ");
            html.Append("<span class='contributor'>");
            html.Append(hmedia.Contributor);
            html.Append("</span> --");
            html.Append("<a class='enclosure' href='");
            html.Append(hmedia.Enclosure);
            html.Append("' type='");
            html.Append(hmedia.MediaType);
            html.Append("'>");
            html.Append(hmedia.Enclosure);
            html.Append("</a>");
            html.Append("</div>");
            return html.ToString();

        }
        private hMedia GetContent(IWin32Window dialogOwner)
        {
            using (contactForm form = new contactForm())
            {
                hMedia c = null;
                DialogResult result = form.ShowDialog(dialogOwner);

                if ((result == DialogResult.OK) && (form.c !=null))
                {
                    c = form.c;
                }
                return c;
            }
        }
    }
    public class hMedia : INotifyPropertyChanged

    {
        public hMedia()
        {

        }
        private string enclosure;

        public string Enclosure
        {
            get { return enclosure; }
            set
            {
                enclosure = value; NotifyPropertyChanged("Enclosure");
            }
        }
        private string fn;

        public string FN
        {
            get { return fn; }
            set { fn = value; NotifyPropertyChanged("FN"); }
        }
        private string contributor;

        public string Contributor 
        {
            get { return contributor; }
            set { contributor = value; NotifyPropertyChanged("Contributor"); }
        }
        private string photo;

        public string Photo
        {
            get { return photo; }
            set { photo = value; NotifyPropertyChanged("Photo"); }
        }
        private string player;

        public string Player 
        {
            get { return player; }
            set { player = value; NotifyPropertyChanged("Player"); }
        }
        private string mediaType;

        public string MediaType
        {
            get { return mediaType; }
            set { mediaType = value; NotifyPropertyChanged("MediaType"); }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }


    }
}